<body>
<script
        src="https://www.paypal.com/sdk/js?client-id=Af4_IeJxGXrU9_uYAm-Z2jfEoWS-FiiM-Nb7fPc2OkFJ5IIAYKWtedmqoHS36C-1gJX63TLrk1PrQBUi&components=messages,buttons&debug=true">
</script>
{{--<script
src="https://www.paypal.com/sdk/js?client-id=ASp8-Ormgi7Ze88GoQpF04a8RRVC5Yna4z-LMUf3-YfMo8RfxuMlp6BUWaPQRfFM-q40SCLsOz0vais_&components=messages,buttons&debug=true"
>--}}

</script>
<div
        class="productdetail_paypal_message"
        data-pp-message
        data-pp-style-layout="text"
        data-pp-style-logo-type="inline"
        data-pp-style-text-color="black"
        data-pp-style-text-size="14"
        data-pp-buyerCountry="US"
        data-pp-amount="146.10">
</div>
<div id="paypal-button-container"></div>

<script>

    paypal.Buttons({
        commit:true,
        createOrder: function () {
            return fetch('/createOrder', {
                method: 'get',

                headers: {
                    'content-type': 'application/json'
                }
            }).then(function (res) {
                return res.json();
            }).then(function (data) {
                console.log(data);
                return data.token;
            });
        },
        onApprove: function (data) {
            console.log(data);

            return fetch('/ordersCaptureRequest', {
                method: 'post',
                headers: {
                    'content-type': 'application/json'
                },
                body: JSON.stringify({
                    token: data.orderID,
                    payerID: data.payerID
                })
            }).then(function(res){
                return res.json();
            }).then(function(data){
                console.log(data);
            });
        }
    }).render('#paypal-button-container');
</script>
</body>
